package com.myacg.editor.common.unit.panel.mobilepanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.RoundRectangle2D;
import java.util.UUID;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;

import com.myacg.editor.common.unit.panel.base.DefaultPanelBar;
import com.myacg.editor.common.utils.JFrameUtils;
/**
 * 可被拖动的窗体
 * @author Administrator
 *
 */
public abstract class MobilePanel extends JPanel{
	private final String id;
	private DefaultPanelBar  panelBar ;
	private Color backgroundColor;
	private Color borderColor;
	public MobilePanel(String panelName) {
		this.id = UUID.randomUUID().toString().toLowerCase();
		this.setLayout(new BorderLayout());
		//初始化窗体
		this.setPanelBarEvent(panelName);
		//加到顶端
		this.add(panelBar,BorderLayout.NORTH);
		backgroundColor = new Color(240, 240, 240,200);
		borderColor  = new Color(200, 200, 200,200);
		this.setOpaque(false);
		this.updateUI();
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		 RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, getWidth()-1, getHeight()-1, 8,8);
		 Graphics2D g2=(Graphics2D) g;
		 g2.setColor(backgroundColor);
		 g2.fill(roundedRectangle);
		 g2.setColor(borderColor);
		 g2.draw(roundedRectangle);
	}
	
	private void setPanelBarEvent(String panelName){
		panelBar = new DefaultPanelBar(panelName,35) {
			@Override
			protected void paintComponent(Graphics g) {
				super.paintComponent(g);
				 RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, getWidth()-1, getHeight()-1, 8,8);
				 Graphics2D g2=(Graphics2D) g;
				 g2.setColor(borderColor);
				 g2.draw(roundedRectangle);
			}
			@Override
			public void hideEvent() {
				MobilePanel.this.hideEvent();
			}
			@Override
			public void closeEvent() {
				MobilePanel.this.closeEvent();
			}
		};
	}
	//推迟点击菜单栏触发的按钮
	public abstract  void  closeEvent();
	public abstract  void  hideEvent();
	
	public String getId() {
		return id;
	}
	public DefaultPanelBar getPanelBar() {
		return panelBar;
	}
	public void setPanelBar(DefaultPanelBar panelBar) {
		this.panelBar = panelBar;
	}
	
}
